package test;

import java.awt.Point;
import engine.Collision;
import engine.Sprite;

public class MarioEnemyCollision implements Collision {
    private final int FUDGE_FACTOR = 5;
    public void applyCollision(Sprite a, Sprite b) {
        Mario m = (Mario)a;
        Enemy e = (Enemy)b;
        //mario hits enemy from top
        if (m.getPosition().getY() + m.getBounds().getHeight() < b.getPosition().getY() + FUDGE_FACTOR) {
            e.markForRemoval();
            m.endJump();
            m.startJump();
        }
        else {
            int posOffset = 0;
            if (m.getPosition().getX() + m.getBounds().getWidth() < b.getPosition().getX() + FUDGE_FACTOR) {
                posOffset = -5;
            }
            else if (m.getPosition().getX() + FUDGE_FACTOR > b.getPosition().getX() + b.getBounds().getWidth()) {
                posOffset = 5;
            }
            m.changeSpeed(new Point(0,0));
            m.setPosition(new Point((int)m.getPosition().getX() + posOffset, (int)m.getPosition().getY()));
            m.damage();
        }
    }
}
